package com.wgchao.patientcenter.mapstruct.mapper.expand;

import com.wgchao.patientcenter.domain.entity.MdmpGrxx;
import com.wgchao.patientcenter.domain.entity.MdmpZddmCommon;
import com.wgchao.patientcenter.domain.repository.MdmpZddmCommonRepository;
import com.wgchao.patientcenter.mapstruct.DTOMapper;
import com.wgchao.patientcenter.mapstruct.dto.MdmpGrxxDTO;
import com.wgchao.patientcenter.mapstruct.mapper.MdmpGrxxMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.security.jca.GetInstance;

import java.util.List;

/**
 * @ClassName: MdmpGrxxMapperExpand
 * @author: wgchao
 * @createTime: 2019/11/3 1:56 PM
 * @Description: TODO
 */
@Component
public class MdmpGrxxMapperExpand implements DTOMapper<MdmpGrxx, MdmpGrxxDTO> {

    private MdmpGrxx grxx;

    public MdmpGrxxMapperExpand setInstance(MdmpGrxx grxx){
        this.grxx = grxx;
        return this;
    }

    @Autowired
    private MdmpGrxxMapper grxxMapper;
    @Autowired
    private MdmpZddmCommonRepository zddmCommonRepository;

    @Override
    public MdmpGrxx toEntity(MdmpGrxxDTO mdmpGrxxDTO) {
        return grxxMapper.toEntity(mdmpGrxxDTO);
    }

    @Override
    public MdmpGrxxDTO toDTO(MdmpGrxx mdmpGrxx) {
        return grxxMapper.toDTO(mdmpGrxx);
    }

    @Override
    public List<MdmpGrxx> toEntity(List<MdmpGrxxDTO> mdmpGrxxDTOS) {
        return grxxMapper.toEntity(mdmpGrxxDTOS);
    }

    @Override
    public List<MdmpGrxxDTO> toDTO(List<MdmpGrxx> mdmpGrxxes) {
        return grxxMapper.toDTO(mdmpGrxxes);
    }

    public MdmpGrxxDTO getExtInfos(MdmpGrxxDTO grxxDTO) {
        //民族
        if(grxx.getMz() != null){
            MdmpZddmCommon zddmCommon = zddmCommonRepository.findFirstByZdlbAndZddm("mz", grxx.getMz());
            if(zddmCommon != null){
                grxxDTO.setMzName(zddmCommon.getZdms());
            }
        }

        //性别
        if(grxx.getSex() != null){
            MdmpZddmCommon zddmCommon = zddmCommonRepository.findFirstByZdlbAndZddm("sex", grxx.getSex());
            if(zddmCommon != null){
                grxxDTO.setSexName(zddmCommon.getZdms());
            }
        }

        //教育程度
        if(grxx.getEdu() != null){
            MdmpZddmCommon zddmCommon = zddmCommonRepository.findFirstByZdlbAndZddm("edu", grxx.getEdu());
            if(zddmCommon != null){
                grxxDTO.setEduName(zddmCommon.getZdms());
            }
        }

        //婚姻状态
        if(grxx.getMarry() != null){
            MdmpZddmCommon zddmCommon = zddmCommonRepository.findFirstByZdlbAndZddm("marry", grxx.getMarry());
            if(zddmCommon != null){
                grxxDTO.setMarryName(zddmCommon.getZdms());
            }
        }

        //户口性质
        if(grxx.getHkxz() != null){
            MdmpZddmCommon zddmCommon = zddmCommonRepository.findFirstByZdlbAndZddm("hk", grxx.getHkxz());
            if(zddmCommon != null){
                grxxDTO.setHkxzName(zddmCommon.getZdms());
            }
        }
        return grxxDTO;
    }
}
